package com.huilan.hgt.service.impl;

import com.huilan.hgt.entity.AttachmentCatalogue;
import com.huilan.hgt.mapper.AttachmentCatalogueMapper;
import com.huilan.hgt.service.AttachmentCatalogueService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 附件目录表 服务实现类
 * </p>
 *
 * @author ghy
 * @since 2018-11-22
 */
@Service
public class AttachmentCatalogueServiceImpl extends ServiceImpl<AttachmentCatalogueMapper, AttachmentCatalogue> implements AttachmentCatalogueService {

    /**
     * 批量保存附件至指定目录
     *
     * @param catalogueId
     * @param attachmentIds
     * @return
     */
    @Override
    public boolean save(Integer catalogueId, String[] attachmentIds) {

        List<AttachmentCatalogue> attachmentCatalogueList = new ArrayList<>();
        for(String attachmentId:attachmentIds){
            AttachmentCatalogue attachmentCatalogue = new AttachmentCatalogue();
            attachmentCatalogue.setCatalogueId(catalogueId)
                    .setAttachmentId(Integer.parseInt(attachmentId));
            attachmentCatalogueList.add(attachmentCatalogue);
        }
        return this.saveBatch(attachmentCatalogueList);
    }
}
